package javacafe.serviceimple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacafe.dao.StudyDAO;
import javacafe.daoimpl.StudyDAOImpl;
import javacafe.dto.study.StudyAuthMgrDTO;
import javacafe.dto.study.StudyDTO;
import javacafe.service.StudyService;

public class StudyServiceImpl implements StudyService {
	
	private static StudyService service = null;
	private static StudyDAO dao = null;
	
	public static StudyService getInstance(){
		if (service == null) {
			service = new StudyServiceImpl();
		}
		return service;
	}
	
	public StudyServiceImpl() {
		dao = StudyDAOImpl.getInstance();
	}

	@Override
	public void createStudy(StudyDTO dto) {
		StudyDAO dao = new StudyDAOImpl();
		dao.createStudy(dto);
	}

	@Override
	public List<StudyDTO> getStudyList() {
		return dao.getStudyList(0);
	}
	@Override
	public List<StudyDTO> getMyStudyList(int mNo) {
		return dao.getStudyList(mNo);
	}

	@Override
	public StudyDTO getStudyInfo(int study_no) {
		return dao.getStudyInfo(study_no);
	}

	@Override
	public void setBackground(int studyNo, String studyBackground) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("study_no", studyNo);
		map.put("study_background", studyBackground);
		dao.setBackground(map);
	}

	@Override
	public List<StudyAuthMgrDTO> getStudyMemberAuthList(int studyNo) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("study_no", studyNo);
		return dao.getStudyMemberAuthList(map);
	}

	@Override
	public void updateAuth(String sauthName, int[] mNo) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("sauth_name", sauthName);
		map.put("m_no", mNo);
		
		dao.updateAuth(map);
	}

	@Override
	public void withdrawalMember(int mNo, int studyNo) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("m_no", mNo);
		map.put("study_no", studyNo);
		
		dao.withdrawalStudyMember(map);
	}
}
